package com.topsun.framework.common.core.util;


import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONException;
import com.alibaba.fastjson2.JSONObject;

/**
 * 
 * @author: 皮皮
 * @date: 2020/9/25 11:19 AM
 */
public class JsonUtil {

    public static JSONObject parseJsonObject(String body) {

        if (JSON.isValidObject(body)) {
            return JSON.parseObject(body);
        }
        throw new JSONException("数据格式错误，无法解析为Json对象");
    }

    public static JSONArray parseJsonArray(String body) {
        if (JSON.isValidArray(body)) {
            return JSON.parseArray(body);
        }
        throw new JSONException("数据格式错误，无法解析为Json数组");
    }
}
